﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Produce.Report
{
    public partial class 生产经营综合统计月报表 : System.Web.UI.Page
    {
        protected string year;
        protected string month;
        protected string RiQiStart;
        protected string RiQiEnd;
        protected string RiQi;
		private string sql;

        /// <summary>
        /// 读入所有的SESSION数据，向VIEW暴露数据项
        /// </summary>
        protected void read_session()
        {
            year = DList_year.SelectedValue;
            month = DList_month.SelectedValue;
        }
		
		/// <summary>
        /// 定义SQL语句
        /// </summary>
        protected void define_sql()
        {
sql=@"
SELECT '一、综合指标','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '(一)工业总产值','万元',1,2,3,4,5,6,7,8
union all
        SELECT '油管','万元',计划产值,实际产值,3,4,5,6,7,8
        FROM [工业总产值]
        WHERE (产品类型ID=1) AND (年份=*年份*) AND (月份=*月份*)
union all
SELECT '套管','万元',1,2,3,4,5,6,7,8
union all
SELECT '(二)销售产值','万元',1,2,3,4,5,6,7,8
union all
SELECT '油管','万元',1,2,3,4,5,6,7,8
union all
SELECT '套管','万元',1,2,3,4,5,6,7,8
union all
SELECT '','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '二、产品产量指标','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '(一)油套管产量','吨',1,2,3,4,5,6,7,8
union all
SELECT '油管','吨',1,2,3,4,5,6,7,8
union all
SELECT '套管','吨',1,2,3,4,5,6,7,8
union all
SELECT '(二)磷化管箍产量','吨/支',1,2,3,4,5,6,7,8
union all
SELECT '油管','吨/支',1,2,3,4,5,6,7,8
union all
SELECT '套管','吨/支',1,2,3,4,5,6,7,8
union all
SELECT '(三)螺纹保护器产量','吨',1,2,3,4,5,6,7,8
union all
SELECT '','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '三、销售指标','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '(一)发货量','吨',1,2,3,4,5,6,7,8
union all
SELECT '油管','吨',1,2,3,4,5,6,7,8
union all
SELECT '套管','吨',1,2,3,4,5,6,7,8
union all
SELECT '(二)销售量','吨',1,2,3,4,5,6,7,8
union all
SELECT '油管','吨',1,2,3,4,5,6,7,8
union all
SELECT '套管','吨',1,2,3,4,5,6,7,8
union all
SELECT '产品库存资金占用','万元',1,2,3,4,5,6,7,8
union all
SELECT '产销率','%',1,2,3,4,5,6,7,8
union all
SELECT '','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '四、质量指标','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '(一)一次校验合格率','',1,2,3,4,5,6,7,8
union all
SELECT '油管','%',1,2,3,4,5,6,7,8
union all
SELECT '套管','%',1,2,3,4,5,6,7,8
union all
SELECT '(二)产品出厂合格率','%',1,2,3,4,5,6,7,8
union all
SELECT '(三)管箍废品量','支',1,2,3,4,5,6,7,8
union all
SELECT '油管','支',1,2,3,4,5,6,7,8
union all
SELECT '套管','支',1,2,3,4,5,6,7,8
union all
SELECT '（四）质量异议合计','项/吨',1,2,3,4,5,6,7,8
union all
SELECT '','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '五、能源消耗','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '新鲜水','吨',1,2,3,4,5,6,7,8
union all
SELECT '电力','KW.H',1,2,3,4,5,6,7,8
union all
SELECT '','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '六、劳资指标','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '人均工业产值','千元/人',1,2,3,4,5,6,7,8
union all
SELECT '从业人员月末人数','人',1,2,3,4,5,6,7,8
union all
SELECT '从业人员劳动报酬','万元',1,2,3,4,5,6,7,8
union all
SELECT '','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '六、财务指标','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
union all
SELECT '主营业务收入','万元',1,2,3,4,5,6,7,8
union all
SELECT '其他','万元',1,2,3,4,5,6,7,8
";
        }

        
		
        protected static DateTime date;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Message.Text = "·准备就绪";
            define_sql();
            if (!this.IsPostBack)
            {
                DList_year.SelectedValue = DateTime.Now.Year.ToString();
                DList_month.SelectedValue = DateTime.Now.Month.ToString();
                sql = sql.Replace("*年份*", DList_year.SelectedValue);
                sql = sql.Replace("*月份*", DList_month.SelectedValue);

            }
            read_session();
            this.SqlDataSource1.SelectCommand = sql;
            this.ViewState["SelectCommand"] = sql;
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }

        protected void DList_year_SelectedIndexChanged(object sender, EventArgs e)
        {
                sql = sql.Replace("*年份*", DList_year.SelectedValue);
                sql = sql.Replace("*月份*", DList_month.SelectedValue);
                this.SqlDataSource1.SelectCommand = sql;
                this.ViewState["SelectCommand"] = sql;
                this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }

        protected void DList_month_SelectedIndexChanged(object sender, EventArgs e)
        {
            sql = sql.Replace("*年份*", DList_year.SelectedValue);
            sql = sql.Replace("*月份*", DList_month.SelectedValue);
            this.SqlDataSource1.SelectCommand = sql;
            this.ViewState["SelectCommand"] = sql;
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }

        //设置表头
        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {

            switch (e.Row.RowType)
            {
                case DataControlRowType.Header:
                    //第一行表头
                    TableCellCollection tcHeader = e.Row.Cells;
                    tcHeader.Clear();
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[0].Attributes.Add("rowspan", "2"); //跨2Row
                    tcHeader[0].Text = "指标名称";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[1].Attributes.Add("rowspan", "2"); //跨2Row
                    tcHeader[1].Text = "单位";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[2].Attributes.Add("colspan", "3"); //跨3Col
                    tcHeader[2].Text = "本月生产";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[3].Attributes.Add("colspan", "3"); //跨3Col
                    tcHeader[3].Text = "全年生产";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[4].Attributes.Add("colspan", "2"); //跨2Col
                    tcHeader[4].Text = "上年同期累计</th></tr><tr>";

                    //第二行表头
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[5].Attributes.Add("colspan", "1");
                    tcHeader[5].Text = "计划";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[6].Attributes.Add("colspan", "1");
                    tcHeader[6].Text = "实际完成";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[7].Attributes.Add("colspan", "1");
                    tcHeader[7].Text = "完成率（%）";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[8].Attributes.Add("colspan", "1");
                    tcHeader[8].Text = "计划";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[9].Attributes.Add("colspan", "1");
                    tcHeader[9].Text = "本月止累计";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[10].Attributes.Add("colspan", "1");
                    tcHeader[10].Text = "全年完成率（%）";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[11].Attributes.Add("colspan", "1");
                    tcHeader[11].Text = "上年同期止累计";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[12].Attributes.Add("colspan", "1");
                    tcHeader[12].Text = "比同期增长（）%</th></tr><tr>";

                    break;
                }
            }

        
    }
    
}
